<!DOCTYPE html>
<html lang="en" class="app">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="Public/common/src/css/bootstrap.css" type="text/css"/>
    <link rel="stylesheet" href="Public/common/src/css/animate.css" type="text/css"/>
    <link rel="stylesheet" href="Public/common/src/css/app.css" type="text/css"/>
    <link rel="stylesheet" href="Public/common/src/css/font-awesome.min.css" type="text/css"/>
</head>
<body class="">
<section class="vbox">
    <section>
        <section class="hbox stretch">
            <!-- /.aside -->
            <section id="content">
                <section class="vbox">
                    <section class="scrollable padder">
                        <ul class="breadcrumb no-border no-radius b-b b-light pull-in">
                            <li><a href="{{U('Admin/Index/home')}}"><i class="fa fa-home"></i> 首页</a></li>
                            <li class="active">货品管理</li>
                        </ul>
                        <section class="panel panel-default">
                            <header class="panel-heading">
                                货品管理
                            </header>

                            <div class="table-responsive">
                            	<form class="form-horizontal" id="form" method="post">
                                <table class="table table-striped b-t b-light">
                                    <thead>
                                    <tr>
							            <td>货品id</td>
							            {{foreach from="$spec" key="$k" value="$v"}}
							            	<td>{{$v['taname']}}</td>
							            {{endforeach}}
							            <td>库存</td>
							            <td>货号</td>
							            <td width="200">操作</td>
                                    </tr>
                                    </thead>
                                    <tbody>                
                                    {{foreach from="$goodsListData" key="$k" value="$v"}}                   
                                    <tr>
                                        <td>{{$v['glid']}}</td>
                                        {{foreach from="$v['spec']" key="$kk" value="$vv"}}
                                        	<td>{{$vv}}</td>
                                        {{endforeach}}
										<td>{{$v['glnumber']}}</td>  
										<td>{{$v['inventory']}}</td>
                                        <td>
                                            <div class="btn-group">
                                                <button data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">操作 <span class="caret"></span></button>
                                                <ul class="dropdown-menu dropdown-menu-right">
                                                    <li><a href="{{U('edit',array('glid'=>$v['glid'],'gid'=>$_GET['gid'],'type_ID'=>$_GET['type_ID']))}}">编辑</a></li>
                                                    <li class="divider"></li>
                                                    <li><a href="javascript:del({{$v['glid']}});">删除</a></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                    {{endforeach}}
                                    {{if value="$is_show"}}
                                    	<tr>
                                    		<td>添加货品</td>
                                    		{{foreach from="$spec" key="$k" value="$v"}}
		                                    <td>
		                                    	<select name="spec[]">
		                                    		<option value="0">--请选择--</option>
		                                    		{{foreach from="$v['select']" key="$kk" value="$vv"}}
		                                    		<option value="{{$vv['gaid']}}">{{$vv['gavalue']}}</option>
		                                    		{{endforeach}}
		                                    	</select>
		                                    </td>
		                                    {{endforeach}}
		                                    <td>
		                                    	<input type="text" name="glnumber" id="" value=""/>
		                                    </td>
		                                    <td>
		                                    	<input type="text" name="inventory" id="" value=""/>
		                                    </td>
		                                    <td></td>
                                    	</tr>
                                    {{endif}}
                                    </tbody>
                                </table>
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset" style="margin-left: 5px;">
                                        	<input type="hidden" value="{{$_GET['gid']}}" name="gid" />
                                        	{{if value="$is_show"}}
                                            <button class="btn btn-primary" id="btn" type="submit">确定添加</button>
                                            {{endif}}
                                        </div>
                                    </div>
                                </form>
                            </div>

                        </section>
                    </section>
                </section>
            </section>
        </section>
    </section>
</section>
<script src="Public/common/src/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="Public/common/src/js/bootstrap.js"></script>
<!-- 公共 -->
<script src="Public/common/js/common.js"></script>
<link rel="stylesheet" href="Public/common/css/common.css">
    <!--异步检测货品是否存在-->
    <script type="text/javascript">
    	$(function(){
    		var specs = $('select[name="spec[]"]');
    		var len = specs.length;
    		specs.change(function(){
    			var remote = {
    				'gid' : {{$_GET['gid']}},
    				'spec':{}
    			}
    			for(var i=0;i<len;i++)
    			{
    				if(specs.eq(i).val()==0)
    				{
    					return;
    				}else
    				{
    					remote.spec[i] = specs.eq(i).val();
    				}
    			}
    			$.post("{{U('ajaxCheck')}}",remote,function(data){
    				if(data==0)
    				{
    					alert('货品已存在');
    					specs.val(0);
    				}
    			})
    		})
    	})
    </script>
    <script type="text/javascript">
    	function del(glid)
    	{
    		if(confirm('确定删除吗？'))
    		{
    			location.href = "index.php?m=Admin&c=GoodsList&a=del&glid=" + glid;
    		}
    	}
    </script>
</body>
</html>